<template>
  <div class="page-hero" v-if="model">
    <div>
      <div class="topbar bg-black-1 py-2 pb-2 px-4 d-flex ai-center" style="padding-top: 8px">
        <img src="../assets/logo.png" height="30" />
        <div class="px-3 flex-1">
          <span class="text-white">王者荣耀</span>
          <span class="ml-2 text-white">攻略战</span>
        </div>
        <router-link tag="div" to="/" class="p-1 px-2 text-primary">更多英雄 &gt;</router-link>
      </div>

      <div class="top header-hero" :style="{'background-image': `url(${model.banner})`}">
        <div class="info d-flex flex-column h-100 jc-end text-white p-3">
          <div>
            <div class="fs-xxs">{{model.title}}</div>
            <h2 class="my-2">{{model.name}}</h2>
            <div class="fs-xxs text-gery">{{model.categories.map( v=> v.name ).join('/')}}</div>
            <div class="d-flex jc-between pt-2">
              <div v-if="model.scores" class="ai-center">
                <span>难度</span>
                <span class="badge mx-1 bg-primary difficult">{{model.scores.difficult}}</span>
                <span>技能</span>
                <span class="badge mx-1 skills">{{model.scores.skills}}</span>
                <span>攻击</span>
                <span class="badge mx-1 attack">{{model.scores.attack}}</span>
                <span>生存</span>
                <span class="badge mx-1 survive">{{model.scores.survive}}</span>
              </div>
              <router-link to="/" tag="span" class="fs-sm text-white">皮肤2 &gt;</router-link>
            </div>
          </div>
        </div>
      </div>
      <!-- end of top -->
      <div>
        <div class="px-3 bg-white">
          <div class="nav d-flex py-3 border-bottom" style="justify-content: space-around;">
            <div class="nav-item active">
              <div class="nav-link">英雄初识</div>
            </div>
            <div class="nav-item">
              <div class="nav-link">进阶攻略</div>
            </div>
          </div>
        </div>
        <swiper>
          <swiper-slide class="mb-3">
            <!-- 技能区域 -->
            <div class="pb-3 bg-white px-3 border-bottom">
              <div class="p-3 mb-3 bg-white">
                <div class="d-flex">
                  <router-link tag="button" class="btn bg-white flex-1 btn-lg py-3" to="/">
                    <i class="iconfont icon-menu"></i>
                    英雄介绍视频
                  </router-link>
                  <router-link tag="button" class="btn flex-1 bg-white ml-2 btn-lg" to="/">
                    <i class="iconfont icon-menu"></i>
                    一键识英雄
                  </router-link>
                </div>
              </div>

              <!-- 技能图片 -->
              <div class="skills-box">
                <div class="d-flex jc-around">
                  <img
                    v-for="(item, i) in model.skills"
                    :key="item.name"
                    class="icon"
                    @click="currentSkillIndex = i"
                    :class="{ imgactive: currentSkillIndex === i}"
                    :src="item.icon"
                    width="70"
                    height="70"
                    :alt="item.name"
                  />
                </div>
                <!-- 技能描述 -->
                <div v-if="currentSkill">
                  <div class="d-flex pt-4 pb-3">
                    <h3 class="m-0">{{currentSkill.name}}</h3>
                    <span
                      class="text-grey-1 ml-4"
                    >（冷却值：{{currentSkill.delay}} 消耗：{{currentSkill.cost}})</span>
                  </div>
                  <p class="pb-4">{{currentSkill.description}}</p>
                  <div class="pt-4 pb-2 border-top text-grey-1">小提示：{{currentSkill.tips}}</div>
                </div>
              </div>
            </div>

            <!-- 装备 -->
            <m-card plain icon="menu" title="出装推荐" class="hero-items">
              <div class="fs-xl">顺风出装</div>
              <div class="d-flex my-3 jc-around border-bottom pb-4">
                <div v-for="item in model.items1" :key="item.name">
                  <img :src="item.icon" class="icon" />
                  <div class="mt-3">{{item.name}}</div>
                </div>
              </div>

              <div class="fs-xl">逆风出装</div>
              <div class="d-flex my-3 jc-around border-bottom pb-4">
                <div v-for="item in model.items2" :key="item.name">
                  <img :src="item.icon" class="icon" />
                  <div class="mt-3">{{item.name}}</div>
                </div>
              </div>
            </m-card>

            <!-- 使用技巧 -->
            <m-card plain icon="menu" title="使用技巧">
              <p class="m-0 lh-1">{{model.usageTips}}</p>
            </m-card>

            <!-- 对战技巧 -->
            <m-card plain  icon="menu" title="对战技巧">
              <p class="m-0 lh-1">{{model.battleTips}}</p>
            </m-card>

            <!-- 团战思路 -->
            <m-card plain icon="menu" title="团战思路">
              <p class="m-0 lh-1">{{model.teamTips}}</p>
            </m-card>

            <!-- 搭档 -->
            <m-card plain icon="menu" title="英雄关系">
              <div class="border-bottom pb-4">
                <div class="fs-xl">最佳搭档</div>
                <div class="d-flex pt-4" v-for="item in model.partners" :key="item.name">
                  <img :src="item.hero.avatar" height="50" />
                  <p class="flex-1 ml-3 m-0">{{item.description}}</p>
                </div>
              </div>
            </m-card>
          </swiper-slide>
          <!-- end of one -->
          <swiper-slide></swiper-slide>
        </swiper>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: {
      required: true
    }
  },
  data() {
    return {
      model: null,
      currentSkillIndex: 0
    };
  },
  created() {
    this.fetch();
  },
  computed: {
    currentSkill() {
      return this.model.skills[this.currentSkillIndex];
    }
  },
  methods: {
    async fetch() {
      const response = await this.$http.get(`heroes/${this.id}`);
      this.model = response.data;
    }
  }
};
</script>

<style lang="scss" scoped>
.lh-1 {
  line-height: 1.6923rem;
}
.page-hero {
  .top {
    overflow: hidden;
    height: 50vw;
    background-position: top center;
    background-size: auto 100%;
  }

  .info {
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8));
    .badge {
      width: 1rem;
      height: 1rem;
      line-height: 1rem;
      text-align: center;
      font-size: 0.75rem;
      border-radius: 50%;
      padding: 0 4px;
      border: 1px solid rgba(255, 255, 255, 0.2);
    }
    .skills {
      background-color: navy;
    }
    .attack {
      background-color: saddlebrown;
    }
    .survive {
      background-color: grey;
    }
  }
  .skills-box {
    img.icon {
      border-radius: 45%;
      border: 2px solid #ffffff;
      &.imgactive {
        border-color: #d59b40;
      }
    }
  }
  .hero-items {
    img.icon {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }
  }
}
</style>